package fr.afcepf.atod16.groupe1.projet1.entities.client;

import fr.afcepf.atod16.groupe1.projet1.entities.Entite;
import fr.afcepf.atod16.groupe1.projet1.entities.commande.Commande;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * L'entité compte client
 * @author cedric
 */
@Entity
@Table(name = "comptes_clients")
public class CompteClient implements Serializable, Entite {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")
    private Integer id;
    @Column(name="pass", nullable = false, length = 32)
    private String pass;
    @Column(name="civilite", nullable = false, length = 16)
    private String civilite;
    @Column(name="nom", nullable = false, length = 100)
    private String nom;
    @Column(name="prenom", nullable = false, length = 100)
    private String prenom;
    @Column(name="adresse", nullable = false)
    private String adresse;
    @Column(name="code_postal", nullable = false, length = 5)
    private String codePostal;
    @Column(name="ville", nullable = false, length = 100)
    private String ville;
    @Column(name="email", nullable = false, unique = true)
    private String email;
    @Column(name="tel_fixe", length = 16)
    private String telFixe;
    @Column(name="tel_mobile", length = 16)
    private String telMobile;
    @Column(name="actif", nullable = false)
    private Boolean actif;
    @OneToMany
    @JoinColumn(name = "compte_client_id", nullable = false)
    private List<Commande> commandes;

    public CompteClient() {
    }

    public CompteClient(Integer id, String pass, String civilite,
            String nom, String prenom, String adresse, String codePostal,
            String ville, String email, String telFixe, String telMobile,
            Boolean actif, List<Commande> commandes) {
        this.id = id;
        this.pass = pass;
        this.civilite = civilite;
        this.nom = nom;
        this.prenom = prenom;
        this.adresse = adresse;
        this.codePostal = codePostal;
        this.ville = ville;
        this.email = email;
        this.telFixe = telFixe;
        this.telMobile = telMobile;
        this.actif = actif;
        this.commandes = commandes;
    }

    @Override
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getCivilite() {
        return civilite;
    }

    public void setCivilite(String civilite) {
        this.civilite = civilite;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getPrenom() {
        return prenom;
    }

    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }

    public String getAdresse() {
        return adresse;
    }

    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    public String getCodePostal() {
        return codePostal;
    }

    public void setCodePostal(String codePostal) {
        this.codePostal = codePostal;
    }

    public String getVille() {
        return ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTelFixe() {
        return telFixe;
    }

    public void setTelFixe(String telFixe) {
        this.telFixe = telFixe;
    }

    public String getTelMobile() {
        return telMobile;
    }

    public void setTelMobile(String telMobile) {
        this.telMobile = telMobile;
    }

    public Boolean getActif() {
        return actif;
    }

    public void setActif(Boolean actif) {
        this.actif = actif;
    }

    public List<Commande> getCommandes() {
        return commandes;
    }

    public void setCommandes(List<Commande> commandes) {
        this.commandes = commandes;
    }

    @Override
    public String toString() {
        return "CompteClient [id=" + id + ", pass=" + pass
                + ", civilite=" + civilite + ", nom=" + nom + ", prenom="
                + prenom + ", adresse=" + adresse + ", codePostal="
                + codePostal + ", ville=" + ville + ", email=" + email
                + ", telFixe=" + telFixe + ", telMobile=" + telMobile
                + ", actif=" + actif + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((actif == null) ? 0 : actif.hashCode());
        result = prime * result + ((adresse == null) ? 0 : adresse.hashCode());
        result = prime * result
                + ((civilite == null) ? 0 : civilite.hashCode());
        result = prime * result
                + ((codePostal == null) ? 0 : codePostal.hashCode());
        result = prime * result + ((email == null) ? 0 : email.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((nom == null) ? 0 : nom.hashCode());
        result = prime * result + ((pass == null) ? 0 : pass.hashCode());
        result = prime * result + ((prenom == null) ? 0 : prenom.hashCode());
        result = prime * result + ((telFixe == null) ? 0 : telFixe.hashCode());
        result = prime * result
                + ((telMobile == null) ? 0 : telMobile.hashCode());
        result = prime * result + ((ville == null) ? 0 : ville.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        CompteClient other = (CompteClient) obj;
        if (actif == null) {
            if (other.actif != null) {
                return false;
            }
        } else if (!actif.equals(other.actif)) {
            return false;
        }
        if (adresse == null) {
            if (other.adresse != null) {
                return false;
            }
        } else if (!adresse.equals(other.adresse)) {
            return false;
        }
        if (civilite == null) {
            if (other.civilite != null) {
                return false;
            }
        } else if (!civilite.equals(other.civilite)) {
            return false;
        }
        if (codePostal == null) {
            if (other.codePostal != null) {
                return false;
            }
        } else if (!codePostal.equals(other.codePostal)) {
            return false;
        }
        if (email == null) {
            if (other.email != null) {
                return false;
            }
        } else if (!email.equals(other.email)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (nom == null) {
            if (other.nom != null) {
                return false;
            }
        } else if (!nom.equals(other.nom)) {
            return false;
        }
        if (pass == null) {
            if (other.pass != null) {
                return false;
            }
        } else if (!pass.equals(other.pass)) {
            return false;
        }
        if (prenom == null) {
            if (other.prenom != null) {
                return false;
            }
        } else if (!prenom.equals(other.prenom)) {
            return false;
        }
        if (telFixe == null) {
            if (other.telFixe != null) {
                return false;
            }
        } else if (!telFixe.equals(other.telFixe)) {
            return false;
        }
        if (telMobile == null) {
            if (other.telMobile != null) {
                return false;
            }
        } else if (!telMobile.equals(other.telMobile)) {
            return false;
        }
        if (ville == null) {
            if (other.ville != null) {
                return false;
            }
        } else if (!ville.equals(other.ville)) {
            return false;
        }
        return true;
    }
}
